package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.operamask.OperaMaskConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.operamask.OperaMaskMgr;

import java.util.ArrayList;
import java.util.List;

public class OperaMaskRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        OperaMaskConfig config = OperaMaskMgr.getConfig();
        if (config != null) {
            // 体力道具换积分
            List<String> paramList = new ArrayList<>();
            long recycleTime = config.getActivityInfo().getEndTime() * 1000L + 600 * 1000;
            paramList.add(String.valueOf(config.getEnergyItemId()));
            paramList.add(String.valueOf(config.getScoreItemId()));
            paramList.add("1");
            paramList.add(config.getActivityInfo().getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(config.getEnergyItemId(), activityType, 2, recycleTime, paramList);
            // 清空金瓜子
            long recycleTime2 = config.getActivityInfo().getEndShowTime() * 1000L + 600 * 1000;
            ActivityItemRecycleMgr.addRecycleItemData(config.getJinGuaZiItemId(), activityType, 2, recycleTime2, new ArrayList<>());
            // 随机卡换积分
            List<String> cardParamList = new ArrayList<>();
            long cardRecycleTime = config.getActivityInfo().getEndTime() * 1000L + 600 * 1000;
            cardParamList.add(String.valueOf(config.getRandomSkillItemId()));
            cardParamList.add(String.valueOf(config.getScoreItemId()));
            cardParamList.add("0");
            cardParamList.add(config.getActivityInfo().getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(config.getRandomSkillItemId(), activityType, 2, cardRecycleTime, cardParamList);
        }
    }

    @Override
    public boolean isActivityRunning() {
        OperaMaskConfig config = OperaMaskMgr.getConfig();
        return config != null && ActivityMgr.activityInTime(config.getActivityInfo());
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.OperaMask.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1) {
            item2Score(userId, data);
        } else {
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }
}
